package com.gdones.bootserver.bus.organization.controller;


import com.gdones.bootserver.bus.organization.dto.Organization;
import com.gdones.bootserver.bus.organization.service.IOrganizationService;
import com.gdones.common.core.annotations.MySysLog;
import com.gdones.common.core.annotations.MySysLogOpration;
import com.gdones.common.core.dto.MyPageBand;
import com.gdones.common.core.dto.MyResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 组织管理
 * @author GaoJingBo
 * @since 2023-04-07
 */
@RestController
@RequestMapping("/sys/org")
@Api(tags={"组织管理操作接口"})
@Slf4j
public class OrganizationController {

    @Resource(name = "organizationServiceImpl")
    private IOrganizationService organizationService;

    /**
     * 分页查询
     * @param organization 查询参数
     * @param page 分页参数
     * @return
     */
    @GetMapping("/pages")
    @ApiOperation("分页查询")
    @MySysLog(modelName="组织管理",methodDesc = "分页查询",methodType = MySysLogOpration.GET)
    public MyResult getParamPage(Organization organization, MyPageBand page){
        log.info("--- 组织管理：分页查询");

        MyResult result = new MyResult();

        try{
            result = organizationService.pages(organization,page);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("分页系统异常");
            result.setCode("9999");
        }

        return result;
    }

    /**
     * 添加-组织
     * @param organization 组织数据
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加-组织")
    @MySysLog(modelName="组织管理",methodDesc = "添加",methodType = MySysLogOpration.POST)
    public MyResult addParam(@RequestBody Organization organization){
        log.info("--- 组织管理：添加-组织");

        MyResult result = new MyResult();

        try{
            result = organizationService.add(organization);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("添加-组织系统异常");
            result.setCode("9999");
        }

        return result;
    }

    /**
     * 修改-组织
     * @param organization 组织数据
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改-组织")
    @MySysLog(modelName="组织管理",methodDesc = "修改",methodType = MySysLogOpration.PUT)
    public MyResult updateParam(@RequestBody Organization organization){
        log.info("--- 组织管理：修改-组织");

        MyResult result = new MyResult();

        try{
            result = organizationService.update(organization);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("修改-组织系统异常");
            result.setCode("9999");
        }

        return result;
    }

    /**
     * 删除-组织
     * @param ids 可批量、单独删除的组织id，逗号分隔
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除-组织")
    @MySysLog(modelName="组织管理",methodDesc = "删除",methodType = MySysLogOpration.DELETE)
    public MyResult updateParam(String ids){
        log.info("--- 组织管理：删除-组织");

        MyResult result = new MyResult();

        try{
            result = organizationService.delete(ids);
        }catch (Exception e){
            e.printStackTrace();
            result.setMsg("删除-组织系统异常");
            result.setCode("9999");
        }

        return result;
    }

}
